package com.liu.lambda;


import com.liu.lambda.entity.Person;

import java.util.ArrayList;
import java.util.List;

public class Lamdba6 {
    public static void main(String[] args) {

        //Lamdba 排序方法

        List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("aaaa",10));
        personList.add(new Person("bbbbb",122));
        personList.add(new Person("ccc",5));
        personList.add(new Person("ddddd",80));
        personList.add(new Person("eeeee",0));
        personList.add(new Person("fffff",87));
        personList.add(new Person("ggggg",22));
        personList.add(new Person("ghhh",555));
        personList.add(new Person("hhhh",33));
        personList.add(new Person("jjjj",11));

        //内部类比较大小

        //先继承Comparator
//        class PersonComparator implements Comparator<Person>{
//            @Override
//            public int compare(Person o1, Person o2) {
//                return o1.getAge() - o2.getAge();
//            }
//        }
//        Collections.sort(personList,new PersonComparator());
//        System.out.println(personList);


        //匿名内部类方式
//        Collections.sort(personList,new Comparator<Person>(){
//            public int compare(Person o1, Person o2) {
//                return o1.getAge() - o2.getAge();
//            }
//        });
//        System.out.println(personList);

        //使用Lamdba 表达式进行排序
        personList.sort((o1, o2) -> {
            return o1.getAge() - o2.getAge();
        });
        System.out.println(personList);





    }


}
